﻿CREATE PROCEDURE [acms].[PostControl_Put]
	@PostVersionId int,
	@TemplateControlId int,
	@Value Xml,
	@ConcurencyId rowversion,
	@IdOut int output,
	@PostIdOut int output,
	@ConcurencyIdOut rowversion output
AS
	if Exists (Select null FROM PostControls where PostVersionId = @PostVersionId and TemplateControlId = @TemplateControlId and Deleted = 0) begin
		update PostControls
		set
			Value = @Value
		where PostVersionId = @PostVersionId
			and TemplateControlId = @TemplateControlId
			and ConcurencyId = @ConcurencyId
			and Deleted = 0
		if @@Rowcount = 0
			return -100
 	end
 	else begin
 		insert into PostControls
 			(PostVersionId, TemplateControlId, Value)
 		values
 			(@PostVersionId, @TemplateControlId, @Value)
 	end
 	
 	select @IdOut = Id, @PostIdOut = PostId, @ConcurencyIdOut = ConcurencyId from PostControl_View where PostVersionId = @PostVersionId and TemplateControlId = @TemplateControlId
	
	
RETURN 0;